#pragma once
#include "SpaceNode.h"
#include "Space.h"
#include "Grid.h"
#include "Vector.h"
#include "RandomHelper.h"
#include <vector>
#include <cmath>

/*
  Copyright 2008 by Alexey Solovyev and University of Pittsburgh
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

namespace org
{
	namespace spark
	{
		using org::spark::data::Grid;
		namespace space
		{


			
			using org::spark::math::RandomHelper;
			using org::spark::math::Vector;
			using org::spark::space::Space;

			class BoundedSpace : public Space
			{
			public:
// Most Java annotations will not have direct native C++ equivalents:
//ORIGINAL LINE: @SuppressWarnings("serial") static class HashGrid2d extends org.spark.data.Grid
				class HashGrid2d : public Grid
				{
				protected:
//ORIGINAL LINE: protected transient SpaceNode[][] nodes;
// WARNING: Since the array size is not known in this declaration, converted this array to a pointer.   call 'delete[]' where appropriate:
					std::vector<std::vector<SpaceNode*>> nodes;

				public:
					HashGrid2d(BoundedSpace *space, int xSize, int ySize);

					virtual SpaceNode *getNode(int x, int y);

					virtual SpaceNode *getNode(double x, double y);


					/// <summary>
					/// Debug method
					/// </summary>
					virtual void verifyIntegrity();

				};

			private:
				//static const long long serialVersionUID = 9016717038171133599LL;

				// Auxiliary class for fast query operations

				// Space coordinates system
			protected:
				 

				// Space topology
				

				/// <returns> Returns the size of the space along x axis </returns>
			public:
				double xMin, xMax, yMin, yMax, xSize, ySize;
				bool wrapX, wrapY;
				virtual double getXSize();

				/// <returns> Returns the size of the space along y axis </returns>
				virtual double getYSize();


				virtual double getXMin();
				virtual double getYMin();
				virtual double getXMax();
				virtual double getYMax();
				virtual bool getWrapX();
				virtual bool getWrapY();

				/// <summary>
				/// The default constructor </summary>
				/// <param name="xMin"> </param>
				/// <param name="xMax"> </param>
				/// <param name="yMin"> </param>
				/// <param name="yMax"> </param>
				/// <param name="wrapX"> </param>
				/// <param name="wrapY"> </param>
				BoundedSpace(double xMin, double xMax, double yMin, double yMax, bool wrapX, bool wrapY);

				/// <summary>
				/// Returns the vector representing the distance between v1 and v2 </summary>
				/// <param name="v1"> </param>
				/// <param name="v2">
				/// @return </param>
				virtual Vector *getVector(Vector *v1, Vector *v2);


				virtual Vector *getRandomPosition();


				virtual double restrictX(double x);


				virtual double restrictY(double y);


			};

		}
	}

	using org::spark::space::SpaceNode;
//----------------------------------------------------------------------------------------
//	
//	
//
//	This class provides the logic to simulate Java rectangular arrays, which are jagged
//	arrays with inner arrays of the same length.
//----------------------------------------------------------------------------------------
class RectangularArrays
{
	
public:
	static std::vector< std::vector<SpaceNode*> > ReturnRectangularSpaceNodeArray(int Size1, int Size2)
	{
		std::vector< std::vector<SpaceNode*> > a;
		 a.resize(Size1);
		for(int i = 0 ; i < Size1 ; ++i)
		{
        //Grow Columns by n
			 a[i].resize(Size2);
		}
		
		return a;
	}
	static double** ReturnRectangularDoubleArray(int Size1, int Size2)
	{
		double** Array = new double*[Size1];
		for (int Array1 = 0; Array1 < Size1; Array1++)
		{
			Array[Array1] = new double[Size2];
		}
		return Array;
	}
};
}